<link rel="stylesheet" href="/static/plugins/zTree_v3/css/zTreeStyle/zTreeStyle.css" type="text/css">
<!--内容开始-->
<section class="content">
	{// 额外HTML代码 }
    {$extra_html_content_top|raw|default=''}
    <!--顶部提示开始-->
    {notempty name="page_tips_top"}
    <div class="alert alert-{$tips_type} alert-dismissable">
        <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
        <p>{$page_tips_top|raw}</p>
    </div>
    {/notempty}
    <!--顶部提示结束-->
    <div class="search">
        <form class="form-inline" action="">
            {notempty name="page_tips_search"}{$page_tips_search|raw}{/notempty}
            <a class="btn btn-flat btn-success m_10 f_r m_t_5" onclick="javascript :history.back(-1)"><i class="fa fa-undo m-r-10"></i>返 回</a>
        </form>
    </div>
    <!--数据表开始-->
    <form method="post" name="myForm" id="myForm" action="">
        <ul id="treeDemo" class="box box-body ztree"></ul>
        <div class="row dd_input_group">
            <div class="form-group">
                <div class="col-xs-7 col-sm-6 col-md-4 col-lg-4">
                    <button type="submit" class="btn btn-flat btn-primary ">提 交</button>
                    <button type="button" class="btn btn-flat btn-default" onclick="javascript :history.back(-1)">返 回</button>
                </div>
            </div>
        </div>
    </form>
</section>
<!--内容结束-->
<SCRIPT type="text/javascript">
		<!--
		var setting = {
			check: {
				enable: true
			},
			data: {
				simpleData: {
					enable: true
				}
			}
		};

		var zNodes =[
			{volist name='list' id='list'}
    			{ id:{$list.id}, pId:{$list.pid}, name:"{$list.title}",checked:{$list.checked?'true':'false'}, open:true},
    		{/volist}
		];

		var code;

		function setCheck() {
			 var zTree = $.fn.zTree.getZTreeObj("treeDemo");
        	zTree.setting.check.chkboxType = { "Y":"ps", "N":"s"}; //勾选 checkbox 对于父子节点的关联关系。默认值：{ "Y": "ps", "N": "ps" }
		}
		function showCode(str) {
			if (!code) code = $("#code");
			code.empty();
			code.append("<li>"+str+"</li>");
		}

		$(document).ready(function(){
			$.fn.zTree.init($("#treeDemo"), setting, zNodes);
			setCheck();
			$("#py").bind("change", setCheck);
			$("#sy").bind("change", setCheck);
			$("#pn").bind("change", setCheck);
			$("#sn").bind("change", setCheck);
		});
		//-->

    $("#myForm").submit(function(){
        var treeObj=$.fn.zTree.getZTreeObj("treeDemo"),
            nodes=treeObj.getCheckedNodes(true),
            v="";
        for(var i=0;i<nodes.length;i++){
            v+=nodes[i].id + ",";
        }
        var id = "{:input('id')}";
        var url = "{:url('accessPost')}";
        $.post(url,{id:id,rules:v},function(result){
            if(result.error == 0){
                $.modal.alertSuccess(result.msg, function (index) {
                    layer.close(index);
                    $.common.jump(result.url);
                });
            }else{
                $.modal.alertError(result.msg);
            }
        })
        return false;
    })

</SCRIPT>
